from problembase import ProblemBase
from dolfin import UnitSquareMesh,Expression,Mesh
from math import pi

class Enright(ProblemBase):
    'Circle (2.5,0,r) rotated by velocity field (-y,x).'
    def __init__(self,options):
        ProblemBase.__init__(self,options)
        
        self.LL = (0,0)
        self.UR = (1,1)
        self.domain = RectangleMesh(self.LL[0],self.LL[1],self.UR[0],self.UR[1],2*self.N,2*self.N)
        
        self.radius = 0.15                              # length of the square side
        self.vStrings = ('-2.*sin(pi*x[1])*cos(pi*x[1])*sin(pi*x[0])*sin(pi*x[0])', 
                         '2.*sin(pi*x[0])*cos(pi*x[0])*sin(pi*x[1])*sin(pi*x[1])')
        
        # string for velocity compononets    
        self.vIsTimeDependent = False               
        self.hasExactSolution = False                # exact is defined
        self.phi_ = Expression('sqrt((x[0]-0.5)*(x[0]-0.5)+(x[1]-0.75)*(x[1]-0.75))-r',r=self.radius)
        self.T = 3    
        self.activeCols = [0,1,2,3]
        ProblemBase.register_variables(self)
        self.ibcExpr = self.exact_solution

    def exact_volume(self):
        '''Return problem specific exact volume.'''
        return pi*self.radius**2
